package chapter21;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * @program: exercise
 * @description: 使用TreeSet类按照字母顺序来显示这些字符串
 * @author: 陈庆彪
 * @create: 2020-02-23 11:14
 **/
public class TestTreeSet {
    public static void main(String[] args) {
        Set set1=new HashSet<>();
        set1.add("beijing");
        set1.add("shanghai");
        set1.add("guangzhou");
        set1.add("NewYork");
        set1.add("San Francisco");

        TreeSet<String> treeSet=new TreeSet<>(set1);
        System.out.println("Sorted Tree Set:"+treeSet);

        System.out.println(treeSet.first());
        System.out.println(treeSet.last());

        System.out.println("headSet(\"NewYork\"):"+treeSet.headSet("NewYork"));//返回newYork之前的元素
        System.out.println("headSet(\"NewYork\"):"+treeSet.tailSet("NewYork"));//返回NewYork之后的元素






    }
}
